package org.gtugs.omsk.funnycats.engine.beans;

public class Vector {
	
	public static Vector make(float x, float y){
		return new Vector(x, y);
	}

	public static Vector makeFromAngle(float module, float angle){
		final float x = module * (float)Math.cos(angle);
		final float y = module * (float)Math.sin(angle);
		
		return new Vector(x,y);
	}
	
	public static Vector zeroVector(){
		return new Vector(0.0f, 0.0f);
	}
	
	public static Vector reverseX(Vector v){
		return Vector.make(-v.x, v.y);
	}
	
	public static Vector reverseY(Vector v){
		return Vector.make(v.x, -v.y);
	}
	
	public static Vector sum(Vector v1, Vector v2){
		return Vector.make(v1.x+v2.x, v1.y+v2.y);
	}
	
	public float length(){
		return (float)Math.sqrt(x*x + y*y);
	}
	
	//Angle between two vectors (x,y) and (1,0)
	public float calculateAngle(){
		float angle, sign = 1f;
		
		if(y < 0)sign = -1f;
		angle = sign*(float)Math.acos(x/Math.sqrt(x*x + y*y));
		
		return angle;
	}
		
	private Vector(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public final float x;
	public final float y;
}
